﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using DTO;


namespace DAO
{
    public class NhanLichChuyenBay_DAO
    {
        public BindingList<NhanLichChuyenBay_DTO> GetNhanLichChuyenBayList()
        {
            BindingList<NhanLichChuyenBay_DTO> listNhanLichChuyenBay = new BindingList<NhanLichChuyenBay_DTO>();
            try
            {
                QLCBDataContext context = new QLCBDataContext();
                var query = from cb in context.ChuyenBays
                            join tb in context.TuyenBays on cb.MaTuyenBay equals tb.MaTuyenBay
                            select new
                            {
                                cb.MaChuyenBay,
                                tb.MaTuyenBay,
                                tb.SanBayDi,
                                tb.SanBayDen,
                                cb.ThoiGianBay,
                                cb.Ngay_Gio,

                                cb.SoLuongGheHang1,
                                cb.SoLuongGheHang2,
                            };
                int mSTT = 1;
                foreach (var nl in query)
                {
                    NhanLichChuyenBay_DTO DTO = new NhanLichChuyenBay_DTO();
                    DTO.STT = mSTT;
                    DTO.ChuyenBay = nl.MaChuyenBay;
                    DTO.TuyenBay = nl.MaTuyenBay;
                    DTO.SanBayDi = nl.SanBayDi;
                    DTO.SanBayDen = nl.SanBayDen;
                    DTO.ThoiGianBay = (int)nl.ThoiGianBay;
                    DTO.NgayGio = (DateTime) nl.Ngay_Gio;
                    DTO.SoLuongGheHang1 = (int)nl.SoLuongGheHang1;
                    DTO.SoLuongGheHang2 = (int)nl.SoLuongGheHang2;
                    DTO.DonGiaVe1 = float.Parse(DonGiaVe_DAO.DonGia(DTO.TuyenBay, "HV001"));
                    DTO.DonGiaVe2 = float.Parse(DonGiaVe_DAO.DonGia(DTO.TuyenBay, "HV002"));
                    listNhanLichChuyenBay.Add(DTO);
                    mSTT++;
                }
            }
            catch (System.Exception ex)
            {
                string str = ex.Message;
            }
            return listNhanLichChuyenBay;
        }
    }
}
